// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.QueryDsl;

internal sealed partial class MatchQueryConverter : JsonConverter<MatchQuery>
{
	public override MatchQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		if (reader.TokenType != JsonTokenType.StartObject)
			throw new JsonException("Unexpected JSON detected.");
		reader.Read();
		var fieldName = reader.GetString();
		reader.Read();
		var variant = new MatchQuery(fieldName);
		while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
		{
			if (reader.TokenType == JsonTokenType.PropertyName)
			{
				var property = reader.GetString();
				if (property == "analyzer")
				{
					variant.Analyzer = JsonSerializer.Deserialize<string?>(ref reader, options);
					continue;
				}

				if (property == "auto_generate_synonyms_phrase_query")
				{
					variant.AutoGenerateSynonymsPhraseQuery = JsonSerializer.Deserialize<bool?>(ref reader, options);
					continue;
				}

				if (property == "boost")
				{
					variant.Boost = JsonSerializer.Deserialize<float?>(ref reader, options);
					continue;
				}

				if (property == "fuzziness")
				{
					variant.Fuzziness = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.Fuzziness?>(ref reader, options);
					continue;
				}

				if (property == "fuzzy_rewrite")
				{
					variant.FuzzyRewrite = JsonSerializer.Deserialize<string?>(ref reader, options);
					continue;
				}

				if (property == "fuzzy_transpositions")
				{
					variant.FuzzyTranspositions = JsonSerializer.Deserialize<bool?>(ref reader, options);
					continue;
				}

				if (property == "lenient")
				{
					variant.Lenient = JsonSerializer.Deserialize<bool?>(ref reader, options);
					continue;
				}

				if (property == "max_expansions")
				{
					variant.MaxExpansions = JsonSerializer.Deserialize<int?>(ref reader, options);
					continue;
				}

				if (property == "minimum_should_match")
				{
					variant.MinimumShouldMatch = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.MinimumShouldMatch?>(ref reader, options);
					continue;
				}

				if (property == "operator")
				{
					variant.Operator = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Operator?>(ref reader, options);
					continue;
				}

				if (property == "prefix_length")
				{
					variant.PrefixLength = JsonSerializer.Deserialize<int?>(ref reader, options);
					continue;
				}

				if (property == "query")
				{
					variant.Query = JsonSerializer.Deserialize<object>(ref reader, options);
					continue;
				}

				if (property == "_name")
				{
					variant.QueryName = JsonSerializer.Deserialize<string?>(ref reader, options);
					continue;
				}

				if (property == "zero_terms_query")
				{
					variant.ZeroTermsQuery = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.ZeroTermsQuery?>(ref reader, options);
					continue;
				}
			}
		}

		reader.Read();
		return variant;
	}

	public override void Write(Utf8JsonWriter writer, MatchQuery value, JsonSerializerOptions options)
	{
		if (value.Field is null)
			throw new JsonException("Unable to serialize MatchQuery because the `Field` property is not set. Field name queries must include a valid field name.");
		if (!options.TryGetClientSettings(out var settings))
			throw new JsonException("Unable to retrieve client settings required to infer field.");
		writer.WriteStartObject();
		writer.WritePropertyName(settings.Inferrer.Field(value.Field));
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(value.Analyzer))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(value.Analyzer);
		}

		if (value.AutoGenerateSynonymsPhraseQuery.HasValue)
		{
			writer.WritePropertyName("auto_generate_synonyms_phrase_query");
			writer.WriteBooleanValue(value.AutoGenerateSynonymsPhraseQuery.Value);
		}

		if (value.Boost.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(value.Boost.Value);
		}

		if (value.Fuzziness is not null)
		{
			writer.WritePropertyName("fuzziness");
			JsonSerializer.Serialize(writer, value.Fuzziness, options);
		}

		if (!string.IsNullOrEmpty(value.FuzzyRewrite))
		{
			writer.WritePropertyName("fuzzy_rewrite");
			writer.WriteStringValue(value.FuzzyRewrite);
		}

		if (value.FuzzyTranspositions.HasValue)
		{
			writer.WritePropertyName("fuzzy_transpositions");
			writer.WriteBooleanValue(value.FuzzyTranspositions.Value);
		}

		if (value.Lenient.HasValue)
		{
			writer.WritePropertyName("lenient");
			writer.WriteBooleanValue(value.Lenient.Value);
		}

		if (value.MaxExpansions.HasValue)
		{
			writer.WritePropertyName("max_expansions");
			writer.WriteNumberValue(value.MaxExpansions.Value);
		}

		if (value.MinimumShouldMatch is not null)
		{
			writer.WritePropertyName("minimum_should_match");
			JsonSerializer.Serialize(writer, value.MinimumShouldMatch, options);
		}

		if (value.Operator is not null)
		{
			writer.WritePropertyName("operator");
			JsonSerializer.Serialize(writer, value.Operator, options);
		}

		if (value.PrefixLength.HasValue)
		{
			writer.WritePropertyName("prefix_length");
			writer.WriteNumberValue(value.PrefixLength.Value);
		}

		writer.WritePropertyName("query");
		JsonSerializer.Serialize(writer, value.Query, options);
		if (!string.IsNullOrEmpty(value.QueryName))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(value.QueryName);
		}

		if (value.ZeroTermsQuery is not null)
		{
			writer.WritePropertyName("zero_terms_query");
			JsonSerializer.Serialize(writer, value.ZeroTermsQuery, options);
		}

		writer.WriteEndObject();
		writer.WriteEndObject();
	}
}

[JsonConverter(typeof(MatchQueryConverter))]
public sealed partial class MatchQuery
{
	public MatchQuery(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		if (field is null)
			throw new ArgumentNullException(nameof(field));
		Field = field;
	}

	/// <summary>
	/// <para>Analyzer used to convert the text in the query value into tokens.</para>
	/// </summary>
	public string? Analyzer { get; set; }

	/// <summary>
	/// <para>If `true`, match phrase queries are automatically created for multi-term synonyms.</para>
	/// </summary>
	public bool? AutoGenerateSynonymsPhraseQuery { get; set; }

	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	public float? Boost { get; set; }
	public Elastic.Clients.Elasticsearch.Serverless.Field Field { get; set; }

	/// <summary>
	/// <para>Maximum edit distance allowed for matching.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.Fuzziness? Fuzziness { get; set; }

	/// <summary>
	/// <para>Method used to rewrite the query.</para>
	/// </summary>
	public string? FuzzyRewrite { get; set; }

	/// <summary>
	/// <para>If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to `ba`).</para>
	/// </summary>
	public bool? FuzzyTranspositions { get; set; }

	/// <summary>
	/// <para>If `true`, format-based errors, such as providing a text query value for a numeric field, are ignored.</para>
	/// </summary>
	public bool? Lenient { get; set; }

	/// <summary>
	/// <para>Maximum number of terms to which the query will expand.</para>
	/// </summary>
	public int? MaxExpansions { get; set; }

	/// <summary>
	/// <para>Minimum number of clauses that must match for a document to be returned.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.MinimumShouldMatch? MinimumShouldMatch { get; set; }

	/// <summary>
	/// <para>Boolean logic used to interpret text in the query value.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Operator? Operator { get; set; }

	/// <summary>
	/// <para>Number of beginning characters left unchanged for fuzzy matching.</para>
	/// </summary>
	public int? PrefixLength { get; set; }

	/// <summary>
	/// <para>Text, number, boolean value or date you wish to find in the provided field.</para>
	/// </summary>
	public object Query { get; set; }
	public string? QueryName { get; set; }

	/// <summary>
	/// <para>Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.ZeroTermsQuery? ZeroTermsQuery { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query(MatchQuery matchQuery) => Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query.Match(matchQuery);
}

public sealed partial class MatchQueryDescriptor<TDocument> : SerializableDescriptor<MatchQueryDescriptor<TDocument>>
{
	internal MatchQueryDescriptor(Action<MatchQueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public MatchQueryDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private bool? AutoGenerateSynonymsPhraseQueryValue { get; set; }
	private float? BoostValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Fuzziness? FuzzinessValue { get; set; }
	private string? FuzzyRewriteValue { get; set; }
	private bool? FuzzyTranspositionsValue { get; set; }
	private bool? LenientValue { get; set; }
	private int? MaxExpansionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MinimumShouldMatch? MinimumShouldMatchValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Operator? OperatorValue { get; set; }
	private int? PrefixLengthValue { get; set; }
	private object QueryValue { get; set; }
	private string? QueryNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.ZeroTermsQuery? ZeroTermsQueryValue { get; set; }

	/// <summary>
	/// <para>Analyzer used to convert the text in the query value into tokens.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, match phrase queries are automatically created for multi-term synonyms.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> AutoGenerateSynonymsPhraseQuery(bool? autoGenerateSynonymsPhraseQuery = true)
	{
		AutoGenerateSynonymsPhraseQueryValue = autoGenerateSynonymsPhraseQuery;
		return Self;
	}

	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	public MatchQueryDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	public MatchQueryDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	public MatchQueryDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>Maximum edit distance allowed for matching.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> Fuzziness(Elastic.Clients.Elasticsearch.Serverless.Fuzziness? fuzziness)
	{
		FuzzinessValue = fuzziness;
		return Self;
	}

	/// <summary>
	/// <para>Method used to rewrite the query.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> FuzzyRewrite(string? fuzzyRewrite)
	{
		FuzzyRewriteValue = fuzzyRewrite;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to `ba`).</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> FuzzyTranspositions(bool? fuzzyTranspositions = true)
	{
		FuzzyTranspositionsValue = fuzzyTranspositions;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, format-based errors, such as providing a text query value for a numeric field, are ignored.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> Lenient(bool? lenient = true)
	{
		LenientValue = lenient;
		return Self;
	}

	/// <summary>
	/// <para>Maximum number of terms to which the query will expand.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> MaxExpansions(int? maxExpansions)
	{
		MaxExpansionsValue = maxExpansions;
		return Self;
	}

	/// <summary>
	/// <para>Minimum number of clauses that must match for a document to be returned.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> MinimumShouldMatch(Elastic.Clients.Elasticsearch.Serverless.MinimumShouldMatch? minimumShouldMatch)
	{
		MinimumShouldMatchValue = minimumShouldMatch;
		return Self;
	}

	/// <summary>
	/// <para>Boolean logic used to interpret text in the query value.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> Operator(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Operator? value)
	{
		OperatorValue = value;
		return Self;
	}

	/// <summary>
	/// <para>Number of beginning characters left unchanged for fuzzy matching.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> PrefixLength(int? prefixLength)
	{
		PrefixLengthValue = prefixLength;
		return Self;
	}

	/// <summary>
	/// <para>Text, number, boolean value or date you wish to find in the provided field.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> Query(object query)
	{
		QueryValue = query;
		return Self;
	}

	public MatchQueryDescriptor<TDocument> QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	/// <summary>
	/// <para>Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter.</para>
	/// </summary>
	public MatchQueryDescriptor<TDocument> ZeroTermsQuery(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.ZeroTermsQuery? zeroTermsQuery)
	{
		ZeroTermsQueryValue = zeroTermsQuery;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		if (FieldValue is null)
			throw new JsonException("Unable to serialize field name query descriptor with a null field. Ensure you use a suitable descriptor constructor or call the Field method, passing a non-null value for the field argument.");
		writer.WriteStartObject();
		writer.WritePropertyName(settings.Inferrer.Field(FieldValue));
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (AutoGenerateSynonymsPhraseQueryValue.HasValue)
		{
			writer.WritePropertyName("auto_generate_synonyms_phrase_query");
			writer.WriteBooleanValue(AutoGenerateSynonymsPhraseQueryValue.Value);
		}

		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (FuzzinessValue is not null)
		{
			writer.WritePropertyName("fuzziness");
			JsonSerializer.Serialize(writer, FuzzinessValue, options);
		}

		if (!string.IsNullOrEmpty(FuzzyRewriteValue))
		{
			writer.WritePropertyName("fuzzy_rewrite");
			writer.WriteStringValue(FuzzyRewriteValue);
		}

		if (FuzzyTranspositionsValue.HasValue)
		{
			writer.WritePropertyName("fuzzy_transpositions");
			writer.WriteBooleanValue(FuzzyTranspositionsValue.Value);
		}

		if (LenientValue.HasValue)
		{
			writer.WritePropertyName("lenient");
			writer.WriteBooleanValue(LenientValue.Value);
		}

		if (MaxExpansionsValue.HasValue)
		{
			writer.WritePropertyName("max_expansions");
			writer.WriteNumberValue(MaxExpansionsValue.Value);
		}

		if (MinimumShouldMatchValue is not null)
		{
			writer.WritePropertyName("minimum_should_match");
			JsonSerializer.Serialize(writer, MinimumShouldMatchValue, options);
		}

		if (OperatorValue is not null)
		{
			writer.WritePropertyName("operator");
			JsonSerializer.Serialize(writer, OperatorValue, options);
		}

		if (PrefixLengthValue.HasValue)
		{
			writer.WritePropertyName("prefix_length");
			writer.WriteNumberValue(PrefixLengthValue.Value);
		}

		writer.WritePropertyName("query");
		JsonSerializer.Serialize(writer, QueryValue, options);
		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		if (ZeroTermsQueryValue is not null)
		{
			writer.WritePropertyName("zero_terms_query");
			JsonSerializer.Serialize(writer, ZeroTermsQueryValue, options);
		}

		writer.WriteEndObject();
		writer.WriteEndObject();
	}
}

public sealed partial class MatchQueryDescriptor : SerializableDescriptor<MatchQueryDescriptor>
{
	internal MatchQueryDescriptor(Action<MatchQueryDescriptor> configure) => configure.Invoke(this);

	public MatchQueryDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private bool? AutoGenerateSynonymsPhraseQueryValue { get; set; }
	private float? BoostValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Fuzziness? FuzzinessValue { get; set; }
	private string? FuzzyRewriteValue { get; set; }
	private bool? FuzzyTranspositionsValue { get; set; }
	private bool? LenientValue { get; set; }
	private int? MaxExpansionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MinimumShouldMatch? MinimumShouldMatchValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Operator? OperatorValue { get; set; }
	private int? PrefixLengthValue { get; set; }
	private object QueryValue { get; set; }
	private string? QueryNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.ZeroTermsQuery? ZeroTermsQueryValue { get; set; }

	/// <summary>
	/// <para>Analyzer used to convert the text in the query value into tokens.</para>
	/// </summary>
	public MatchQueryDescriptor Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, match phrase queries are automatically created for multi-term synonyms.</para>
	/// </summary>
	public MatchQueryDescriptor AutoGenerateSynonymsPhraseQuery(bool? autoGenerateSynonymsPhraseQuery = true)
	{
		AutoGenerateSynonymsPhraseQueryValue = autoGenerateSynonymsPhraseQuery;
		return Self;
	}

	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	public MatchQueryDescriptor Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	public MatchQueryDescriptor Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	public MatchQueryDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	public MatchQueryDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>Maximum edit distance allowed for matching.</para>
	/// </summary>
	public MatchQueryDescriptor Fuzziness(Elastic.Clients.Elasticsearch.Serverless.Fuzziness? fuzziness)
	{
		FuzzinessValue = fuzziness;
		return Self;
	}

	/// <summary>
	/// <para>Method used to rewrite the query.</para>
	/// </summary>
	public MatchQueryDescriptor FuzzyRewrite(string? fuzzyRewrite)
	{
		FuzzyRewriteValue = fuzzyRewrite;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, edits for fuzzy matching include transpositions of two adjacent characters (for example, `ab` to `ba`).</para>
	/// </summary>
	public MatchQueryDescriptor FuzzyTranspositions(bool? fuzzyTranspositions = true)
	{
		FuzzyTranspositionsValue = fuzzyTranspositions;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, format-based errors, such as providing a text query value for a numeric field, are ignored.</para>
	/// </summary>
	public MatchQueryDescriptor Lenient(bool? lenient = true)
	{
		LenientValue = lenient;
		return Self;
	}

	/// <summary>
	/// <para>Maximum number of terms to which the query will expand.</para>
	/// </summary>
	public MatchQueryDescriptor MaxExpansions(int? maxExpansions)
	{
		MaxExpansionsValue = maxExpansions;
		return Self;
	}

	/// <summary>
	/// <para>Minimum number of clauses that must match for a document to be returned.</para>
	/// </summary>
	public MatchQueryDescriptor MinimumShouldMatch(Elastic.Clients.Elasticsearch.Serverless.MinimumShouldMatch? minimumShouldMatch)
	{
		MinimumShouldMatchValue = minimumShouldMatch;
		return Self;
	}

	/// <summary>
	/// <para>Boolean logic used to interpret text in the query value.</para>
	/// </summary>
	public MatchQueryDescriptor Operator(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Operator? value)
	{
		OperatorValue = value;
		return Self;
	}

	/// <summary>
	/// <para>Number of beginning characters left unchanged for fuzzy matching.</para>
	/// </summary>
	public MatchQueryDescriptor PrefixLength(int? prefixLength)
	{
		PrefixLengthValue = prefixLength;
		return Self;
	}

	/// <summary>
	/// <para>Text, number, boolean value or date you wish to find in the provided field.</para>
	/// </summary>
	public MatchQueryDescriptor Query(object query)
	{
		QueryValue = query;
		return Self;
	}

	public MatchQueryDescriptor QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	/// <summary>
	/// <para>Indicates whether no documents are returned if the `analyzer` removes all tokens, such as when using a `stop` filter.</para>
	/// </summary>
	public MatchQueryDescriptor ZeroTermsQuery(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.ZeroTermsQuery? zeroTermsQuery)
	{
		ZeroTermsQueryValue = zeroTermsQuery;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		if (FieldValue is null)
			throw new JsonException("Unable to serialize field name query descriptor with a null field. Ensure you use a suitable descriptor constructor or call the Field method, passing a non-null value for the field argument.");
		writer.WriteStartObject();
		writer.WritePropertyName(settings.Inferrer.Field(FieldValue));
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (AutoGenerateSynonymsPhraseQueryValue.HasValue)
		{
			writer.WritePropertyName("auto_generate_synonyms_phrase_query");
			writer.WriteBooleanValue(AutoGenerateSynonymsPhraseQueryValue.Value);
		}

		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (FuzzinessValue is not null)
		{
			writer.WritePropertyName("fuzziness");
			JsonSerializer.Serialize(writer, FuzzinessValue, options);
		}

		if (!string.IsNullOrEmpty(FuzzyRewriteValue))
		{
			writer.WritePropertyName("fuzzy_rewrite");
			writer.WriteStringValue(FuzzyRewriteValue);
		}

		if (FuzzyTranspositionsValue.HasValue)
		{
			writer.WritePropertyName("fuzzy_transpositions");
			writer.WriteBooleanValue(FuzzyTranspositionsValue.Value);
		}

		if (LenientValue.HasValue)
		{
			writer.WritePropertyName("lenient");
			writer.WriteBooleanValue(LenientValue.Value);
		}

		if (MaxExpansionsValue.HasValue)
		{
			writer.WritePropertyName("max_expansions");
			writer.WriteNumberValue(MaxExpansionsValue.Value);
		}

		if (MinimumShouldMatchValue is not null)
		{
			writer.WritePropertyName("minimum_should_match");
			JsonSerializer.Serialize(writer, MinimumShouldMatchValue, options);
		}

		if (OperatorValue is not null)
		{
			writer.WritePropertyName("operator");
			JsonSerializer.Serialize(writer, OperatorValue, options);
		}

		if (PrefixLengthValue.HasValue)
		{
			writer.WritePropertyName("prefix_length");
			writer.WriteNumberValue(PrefixLengthValue.Value);
		}

		writer.WritePropertyName("query");
		JsonSerializer.Serialize(writer, QueryValue, options);
		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		if (ZeroTermsQueryValue is not null)
		{
			writer.WritePropertyName("zero_terms_query");
			JsonSerializer.Serialize(writer, ZeroTermsQueryValue, options);
		}

		writer.WriteEndObject();
		writer.WriteEndObject();
	}
}